package prac8;


/**
 * Generic iterator interface 
 * 
 * @author          Menghong Li
 * @param           <K> type of element 
 * @since           July 2011
 * @knownBugs       none
 */

interface TreeIterator<K, SortedLinkedList> {
    /**
     * Determines whether the iterator has gone through all items
     * already, or there are some left to iterate.
     * 
     * @post        the list is unchanged
     * @return      true if there is an element that has not yet
     *              been iterated over, false otherwise 
     */
    boolean hasNext();

    /**
     * Resets the iterator to its initial state.
     * 
     * @post       current points to the head (and thus previous to null)
     */
    void reset();

    /**
     * Returns the element that is about to be iterated over 
     * If none left, it throws a NoSuchMethodException.
     * 
     * @return      element at the current position 
     * @post        the list is unchanged
     * @post        the element that is about to be iterated over 
     *              or throws NoSuchMethodException if none left
     */
    Pair<K, SortedLinkedList> peek();

    /**
     * Returns the next element that has not been processed and moves to 
     * next one. If all nodes had already been iterated over, it throws
     * a NoSuchMethodException
     * 
     * @return      the next element to be processed
     * @post        the list is unchanged
     * @post        if there is an element that has not yet been iterated
     *              over, it returns it and moves over it. Otherwise 
     *              it throws NoSuchMethodException.
     */
    Pair<K, SortedLinkedList> next() ;

    /**
     * Deletes the element that was next to be processed and moves to the
     * next. If all nodes had already been iterated over, it throws 
     * a NoSuchMethodException
     * 
     * @post        if there is an element that has not yet been iterated
     *              over, it deletes it and moves over it. Otherwise 
     *              it throws NoSuchMethodException.
     * @post        contains exactly the same elements as before, except
     *              for the element that was about to be iterated over.
     */

    // Note that the iterator does not contain an addHere(T newItem) 
    // method, since it could be problematic for a sorted list. 
}

